﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>菜单信息配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script type="text/html" id="barDemo">
 
        <a title="菜单编辑" href="javascript:;" lay-event="editMenu" id="update"><i class="layui-icon">&#xe642;</i></a>
        <a title="权限配置" href="javascript:;" lay-event="setPower" id="setPower"><i class="layui-icon">&#xe631;</i></a>
        <a title="删除信息" href="javascript:;" lay-event="delMenu" id="del"><i class="layui-icon">&#xe640;</i></a>
     
    </script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">

                                <input type="text" name="menuCode" placeholder="菜单编码查询" autocomplete="off" class="layui-input" id="menuCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="menuName" placeholder="菜单名称查询" autocomplete="off" class="layui-input" id="menuName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                               <select id="parentMenu" name="parentMenu">
                                <option value="">所属菜单</option>
                               </select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="btn-view" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>

                        </form>
                    </div>

                    <div class="layui-card-header">
                        <button class="layui-btn" id="btn-update" type="button" onclick="openWin()"><i class="layui-icon"></i>添加</button>
                    </div>

                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var currPage = 1;//首先默认值为1，防止出错
    var dUrl = "../System/getTableList?dataType=menu&condition=";
    /**
    数据加载
    **/
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
              , cols: [[ //标题栏
                { field: 'menuCode', title: '菜单编码', width: 100 }
              , { field: 'menuName', title: '菜单名称', width: 130 }
              , { field: 'menuPath', title: '菜单路径', width: 300 }
              , { field: 'orderNum', title: '序号', width: 65 }
              , { field: 'menuIcon', title: '菜单图标', width: 90 }
              , { field: 'parentsName', title: '所属菜单', width: 100 }
              , { field: 'statusName', title: '是否启用', width: 90 }
              , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 110, fixed: 'right' }
            ]], done: function (res, curr, count) {
       
                  currPage = curr;
                TablePowerHide();
            }

                , url: dUrl + conditon
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 20, 30]
                , limit: 15 //每页默认显示的数量
            ,id:"tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
             if (obj.event == 'delMenu') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data.id);
                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'editMenu') {
                 var str = data.menuName + "-菜单编辑"
                 var conditon = JSON.stringify(FormToJson("qForm"));
                 NewOpenPage('../System/UpdateMenu?dataId=' + data.menuCode, str, "80%", "90%", "tData", currPage, dUrl + conditon);
                }
                else if (obj.event == 'setPower') {
                    var str = data.menuName + "(" + data.menuCode + ")";
                    OpenPage(str+"-权限配置", '../System/MenuOperate?mCode=' + data.menuCode );
                }
            
            });

        });
    }
    $(function () {
        WebPowersShow();
        TopMenu();
        loadData();
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                loadData();
            }
        })
    })
    
    function openWin() {
        InfoOpenPage("../System/UpdateMenu?type=Add", "系统菜单添加", "85%", "90%");
    }
    /**
    删除菜单方法
    **/
    function DelData(dataId) {
        var info = undefined;
        $.ajax({
            url: "../System/DelMenuInfo",
            data: { dataId: dataId },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }
    /**
     * 获取顶级菜单
     * **/
    function TopMenu() {
        $.ajax({
            url: "../System/GetTopMenu",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        if (datas[i]["menuCode"] != "") {
                            $("#parentMenu").append("<option value=\"" + datas[i]["menuCode"] + "\" >" + datas[i]["menuName"] + "(" + datas[i]["menuCode"] + ")" + "</option>");
                        }
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }
</script>